<?php
/**
 *Create by PhpStorm
 *User:Kendy
 *Date:2019/10/11/011
 *Time:16:27
 */
namespace app\admin\model;
use think\Controller;
use think\Model;
use think\Db;
class OrderRefunds extends Model{


    protected $name = 'order_refund';
    /**
     * 根据搜索条件获取所有的退款订单数据
     * @param $where  查询条件
     * @param $offset
     * @param $limit
     * @return mixed
     */
    public function getRefundList($where,$offset, $limit)
    {
        $rdata= $this
            ->alias('or')
            ->join('user u','or.u_id=u.uid','left')
            ->where($where)
            ->field(' or.refund_id,or.order_sn,or.u_id,or.object_type, or.object_id,or.refund_trade_no,or.refund_remark,or.refund_time,or.refund_reson,or.back_money,or.refund_status,or.create_time,u.nickname')
            ->order('refund_id desc')
            ->limit($offset, $limit)
            ->select();
        if(count($rdata)>0)
        {
            foreach ($rdata as $k => $v) {
                $rdata[$k]['refund_status'] = lvOrderRefundstatus($v['refund_status']);
            }
        }
        return $rdata;
    }

    /**
     * 根据搜索条件获取所有的退款订单数量
     * @param $where  查询条件
     * @return mixed
     */
    public function  getRefundListCount($where)
    {
        return $this
            ->alias('or')
            ->join('user u','or.u_id=u.uid','left')
            ->where($where)
             ->order('refund_id desc')
            ->count();
    }
}